package com.day12.study.chat;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * 客户端子线程
 */
public class ClientThread implements Runnable {

    private Socket socket;

    public ClientThread(Socket socket) {
        super();
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream is = socket.getInputStream();
            DataInputStream dis = new DataInputStream(is);
            while (!socket.isClosed()) {
                String msg = dis.readUTF();
                System.out.println(msg);
            }
            dis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
